﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Xiaozilang_Ordering_System
{
    public partial class Comment : Form
    {
        DataTable dt = new DataTable();
        public Comment()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            
                DialogResult sd = MessageBox.Show("是否确定评论?", "提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (sd == DialogResult.OK)   //如果单击“是”按钮
                {
                    if (txtscore.Text != "" && txtscore.Text != "")
                    {
                        string sql2 = string.Format("insert into Comment (PLTime,graded,detailedComments,OrderID,BSID) values('{0}','{1}','{2}','{3}','{4}')", DateTime.Now.ToString(), txtscore.Text, txtevaluate.Text, client.ORDERID, client.BSID);
                        DBHelper.GetNonQuery(sql2);
                        MessageBox.Show("发表成功！");
                    }
                    else
                    {
                        MessageBox.Show("评分或评价未输入！");
                    }
                    this.Close();
                }
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Comment_Load(object sender, EventArgs e)
        {
            //文字背景透明
            lblevaluate.BackColor = Color.Transparent;
            lblscore.BackColor = Color.Transparent;
            label1.BackColor = Color.Transparent;

            string sql1 = string.Format("select * from Comment where OrderID='{0}' and BSID='{1}'", client.ORDERID, client.BSID);
            dt = DBHelper.SelectByAdapter(sql1);
            if (dt.Rows.Count > 0)
            {
                txtscore.Text = dt.Rows[0]["graded"].ToString();
                txtevaluate.Text = dt.Rows[0]["detailedComments"].ToString();
                btnpPublish.Enabled = false;
            }
        }
    }
}
